package org.diysearch.services;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.diysearch.helpers.CategoryHelper;
import org.diysearch.helpers.LinkHelper;
import org.diysearch.helpers.PageHelper;
import org.diysearch.interfaces.Product;
import org.diysearch.products.HtmlProduct;

public class HomePage extends BaseService {
	private static final Log LOG = LogFactory.getLog(HomePage.class);
	private String productArg;
	private String uri;
	
	public HomePage(String productArg) {
		super();
		this.productArg = productArg;
	}
	@Override
	public Product execute() throws Exception {
		Product p = new HtmlProduct();
		
		Map<String,Object> content = new HashMap<String,Object>();
		content.put("message","this is the home page");
		content.put("links", LinkHelper.fetchLinks(new String[] {"-rt","0","-lmt","10"}));
		content.put("editor_picks", LinkHelper.fetchLinks(new String[] {"-ep"}));
		content.put("categories",CategoryHelper.fetchAll());
		if (uri != null) {
			content.put("page", PageHelper.getPage(uri));
		}
		p.setWriter(writer);
		p.setCompleted(productArg, request, response, template, content);
		return p;
	}

	@Override
	public boolean isWriter() {
		return true;
	}
	@Override
	public String getUri() {
		return uri;
	}
	@Override
	public void setUri(String uri) {
		this.uri = uri;
		
	}

}
